// Car 类
class Car(val licensePlate: String, val brand: String, val color: String, val price: Double) {
  def drive(): Unit = println(s"$brand car with plate $licensePlate is driving.")

  def park(): Unit = println(s"$brand car with plate $licensePlate is parked.")

  def refuel(): Unit = println(s"$brand car with plate $licensePlate is refueling.")
}

// ElectricCar 子类
class ElectricCar(
    licensePlate: String,
    brand: String,
    color: String,
    price: Double,
    var batteryCapacity: Double,
    var rangeLeft: Double
) extends Car(licensePlate, brand, color, price) {

  override def drive(): Unit = {
    if (rangeLeft > 0) {
      println(s"Electric $brand car is driving. Range left: $rangeLeft km.")
      rangeLeft -= 10
    } else {
      println("Battery empty! Please recharge.")
    }
  }

  def charge(amount: Double): Unit = {
    rangeLeft += amount
    if (rangeLeft > batteryCapacity) rangeLeft = batteryCapacity
    println(s"Charging complete. New range: $rangeLeft km.")
  }
}

// 测试
object CarTest extends App {
  val car = new Car("ABC-123", "Toyota", "Blue", 20000)
  car.drive()
  car.park()
  car.refuel()

  val electricCar = new ElectricCar("XYZ-789", "Tesla", "Red", 50000, 100, 50)
  electricCar.drive()
  electricCar.charge(30)
  electricCar.drive()
}
